package com.ysqcould.allocation.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.ysqcould.allocation.domain.WxUser;
import com.ysqcould.allocation.mapper.WxUserMapper;
import com.ysqcould.allocation.service.IWxUserService;
import com.ysqcould.common.utils.DateUtils;
import com.ysqcould.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 微信用户
Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@Slf4j
@Service
public class WxUserServiceImpl implements IWxUserService {
    @Autowired
    private WxUserMapper wxUserMapper;

    /**
     * 查询微信用户
     *
     * @param id 微信用户
     *           主键
     * @return 微信用户
     */
    @Override
    public WxUser selectWxUserById(Long id) {
        return wxUserMapper.selectWxUserById(id);
    }

    /**
     * 查询微信用户
     * 列表
     *
     * @param wxUser 微信用户
     * @return 微信用户
     */
    @Override
    public List<WxUser> selectWxUserList(WxUser wxUser) {
        List<WxUser> wxUsersList = wxUserMapper.selectWxUserList(wxUser);
        wxUsersList.stream().filter(p -> StringUtils.isNotEmpty(p.getAddress())).forEach(p -> {
            JSONObject json = JSONObject.parseObject(p.getAddress());
            String name = json.getString("name");
            p.setAddress(name);
        });
        return wxUsersList;
    }

    /**
     * 新增微信用户
     *
     * @param wxUser 微信用户
     * @return 结果
     */
    @Override
    public int insertWxUser(WxUser wxUser) {
        wxUser.setCreateTime(DateUtils.getNowDate());
        return wxUserMapper.insertWxUser(wxUser);
    }

    /**
     * 修改微信用户
     *
     * @param wxUser 微信用户
     * @return 结果
     */
    @Override
    public int updateWxUser(WxUser wxUser) {
        wxUser.setUpdateTime(DateUtils.getNowDate());
        return wxUserMapper.updateWxUser(wxUser);
    }

    /**
     * 批量删除微信用户
     *
     * @param ids 需要删除的微信用户
     *            主键
     * @return 结果
     */
    @Override
    public int deleteWxUserByIds(Long[] ids) {
        return wxUserMapper.deleteWxUserByIds(ids);
    }

    /**
     * 删除微信用户
     * 信息
     *
     * @param id 微信用户
     *           主键
     * @return 结果
     */
    @Override
    public int deleteWxUserById(Long id) {
        return wxUserMapper.deleteWxUserById(id);
    }

}

